<?php
namespace Myth\Data\Model\DbTable;

use Zend\Db;

class Relation implements IRelation
{
    protected $_tables = array();
    
    public function addTable (Table $table, $relationType, $baseTableField, $foreignTableField, $conditions = null)
    {
        $name = $table->getName();
        $this->_tables[$name]['DbTable'] = $table;
        $this->_tables[$name]['baseField'] = $baseTableField;
        $this->_tables[$name]['foreignField'] = $foreignTableField;
        if (null == $conditions) {
            $this->_tables[$name]['condition'] = $baseTableField .
             '=' . $foreignTableField;
        } else {
            $this->_tables[$name]['condition'] = $conditions;
        }
    }
    
    public function getTables ()
    {
        $tables = array();
        foreach ($this->_tables as $t) {
            $tables[] = $t['DbTable'];
        }
        return $tables;
    }
    
    public function getTable ($table)
    {
        foreach ($this->_tables as $name => $t) {
            if ($table == $name) {
                return $t['DbTable'];
            }
        }
        require_once dirname(__FILE__).'/Exception.php';
        throw new Exception('DbTable not found for: '.$table);
    }
    
    public function join(Db\Select $select, $table)
    {
        
    }
}